<template>
  <!-- 头部导航 -->
  <div class="topBanner">
            <div class="m-topBar flex">
                <div @click="backhome">
                    <van-icon name="wap-home-o" size="28px" />
                </div>
                <a href="/"><i>网易严选</i></a>
                <div class="right flex">
                    <div @click="goSearch">
                        <van-icon name="search" size="28px" />
                    </div>
                    <div @click="gocart">
                        <van-icon name="shopping-cart-o" size="28px" />
                    </div>

                </div>
            </div>
        </div>

  <!-- 地址列表 -->

  <div class="addrsList">
    <van-address-list
  v-model="chosenAddressId"
  :list="list"
  default-tag-text="默认"
  @add="onAdd"
  @edit="onEdit"
/>
  </div>

</template>

<script setup lang="ts">
import { AddressList } from 'vant';
import {useRouter} from 'vue-router'
import { ref } from 'vue';
import { showToast } from 'vant';
const router = useRouter()

const backhome = () => {
    router.push('/home')
}
const gocart = () => {
    router.push('/cart')

}
const goSearch = () => {
    router.push('/search')

}
const chosenAddressId = ref('1');
    const list = [
      {
        id: '1',
        name: '张三',
        tel: '13000000000',
        address: '浙江省杭州市西湖区文三路 138 号东方通信大厦 7 楼 501 室',
        isDefault: true,
      },
      {
        id: '2',
        name: '李四',
        tel: '1310000000',
        address: '浙江省杭州市拱墅区莫干山路 50 号',
      },
      {
        id: '3',
        name: '王五',
        tel: '1320000000',
        address: '浙江省杭州市滨江区江南大道 15 号',
      },
    ];

    const onAdd = () => {
      router.push('/addaddress')
    };
    const onEdit = (item:any, index:any) => showToast('编辑地址:' + index);

</script>

<style lang="less" scoped>
//头部导航
.topBanner {
  width: 355px;
  height: 44px;
  line-height: 44px;
  padding: 0 8px 0 12px;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1;
  background-color: #fff;

  &::after {
    content: '';
    display: block;
    clear: both;
  }

  .m-topBar {
    align-items: center;
    justify-content: space-around;
    a i {
      font-style: normal;
      color: black;
    }
    .right{
      align-items: center;
    justify-content: space-around;
    }
  }
}
//地址列表
.addrsList{
  margin-top: 60px;
}
//横向
.flex {
  display: flex;
}
</style>